<template>
	<view>
		<!-- 头部 -->
		<view class="navbar">
			<u-icon @click="navigateBack" class="icon-left" name="arrow-left" color="#fff" size="50"></u-icon>
			<text>健康服务</text>
		</view>
		<!-- 内容 -->
		<view class="" style="margin-top:192rpx">
			<view class="content" v-if='noBind'>
				<view class="">
					<view class="">
						占无服务对象
					</view>
					<view class="">
						请扫码添加！
					</view>
				</view>
				<view class="btn-scan" @click='scanCode'>
					扫码添加
				</view>
			</view>
			<Chat v-else />
		</view>

	</view>
</template>

<script>
	import {
		Chat
	} from './chat.vue'
	export default {
		data() {
			return {
				noBind: false,
			}
		},
		components: {
			Chat
		},
		methods: {
			navigateBack() {
				uni.switchTab({
					url: '../my'
				})
			},
			scanCode() {
				var _this = this;
				uni.scanCode({
					success: function(res) {
						_this.code = res.result;
						_this.bindDevice();
					},
					fail: function(res) {

						uni.showModal({
							title: '设备扫码',
							content: res.message || '设备扫描失败'
						});
					}
				})
			},
			async bindDevice() {

				uni.navigateTo({
					url: '/pages/login/binding/device/device?code=' + this.code
				})
			}
		}
	}
</script>

<style lang='scss' scoped>
	// 头部
	.navbar {
		padding-top: 90rpx;
		padding-bottom: 40rpx;
		width: 750rpx;
		color: #fff;
		background-color: rgb(68, 92, 223);
		position: fixed;
		top: 0
	}

	.navbar>text {
		font-size: 36rpx;
		padding-left: 220rpx;
	}

	.content {
		width: 100%;
		display: flex;
		justify-content: center;
		margin-top: 220rpx;
		font-size: 36rpx;
		flex-direction: column;
		align-items: center;
		color: #999;

		.btn-scan {
			width: 300rpx;
			text-align: center;
			border: 1px solid #4CD964;
			color: #4CD964;
			border-radius: 4rpx;
			font-size: 26rpx;
			margin-top: 120rpx;
			padding: 10rpx 0;
		}
	}
</style>
